package com.gomyb.admin.module.user.service.impl;

import com.gomyb.admin.module.user.model.SysRole;
import com.gomyb.admin.module.user.service.SysRoleService;
import com.gomyb.common.base.BaseDao;
import com.gomyb.common.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019-04-01 16:59:05
 */
@Service
public class SysRoleServiceImpl extends BaseServiceImpl<SysRole, Long> implements SysRoleService {

    @Override
    @Autowired
    public void setDao(BaseDao<SysRole, Long> dao) {
        super.dao = dao;
    }

    @Override
    public List<SysRole> findRolesByUserName(String userName) {
        String sql = "SELECT\n" +
                "\tt3.*\n" +
                "FROM\n" +
                "\tsys_role t3\n" +
                "LEFT JOIN sys_user_role t4 ON t4.role_id = t3.id\n" +
                "LEFT JOIN sys_user t5 ON t5.id = t4.user_id\n" +
                "WHERE\n" +
                "\tt5.username = '" + userName + "';";
        return super.findBySql(sql,SysRole.class);
    }
}
